package com.ai.aiagent.rag;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
@SuppressWarnings("all")
/**
 *@ClassName PgVectorStoreConfig
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/11/17 10:56
 *@Version 1.0     用于实现pgvector数据库的初始化，将数据保存到阿里云中的pgvector数据库中
 */
@Configuration
public class PgVectorStoreConfig {
    @Resource
    VectorStore vectorStore;
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;

//    public void pgVectorStore() {
//        log.info("开始执行pgvector代码");
//        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
//        List<Document> enrichedDocuments  = myKeywordEnricher.enrichDocuments(documents);
//        vectorStore.add(enrichedDocuments);
//        List<Document> results =
//                this.vectorStore.similaritySearch(SearchRequest.builder().query("单身").topK(5).build());
//        log.info("{}", results);
//
//    }
//    @Bean
//    public VectorStore pgVectorStore() {
//        log.info("开始执行pgvector代码");
//        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
//        List<Document> enrichedDocuments  = myKeywordEnricher.enrichDocuments(documents);
//        vectorStore.add(enrichedDocuments);
//        return vectorStore;

    /// /
//    }
//   数据库中有数据的话， 直接从数据库中获取数据即可，不用每次都向数据库中添加数据，
    @Bean
    public  VectorStore pgVectorStore() {
        log.info("初始化向量存储连接");
        return vectorStore;
//
    }
}

